package aeolus.wind.spider.biz.dataobject;

import java.util.HashSet;
import java.util.Set;

import aeolus.wind.spider.biz.constants.Constants;

import com.sleepycat.persist.model.Entity;
import com.sleepycat.persist.model.PrimaryKey;
import com.sleepycat.persist.model.Relationship;
import com.sleepycat.persist.model.SecondaryKey;

/**
 * 相当于能力视图的概念，可以包裹任意多的能力
 * 
 * @author aeoluswind
 */
@Entity
public class AbilityPackage {

    /**
     * 能力视图名
     */
    @PrimaryKey
    private String      id;

    @SecondaryKey(relate = Relationship.MANY_TO_ONE)
    private String      packageName;
    /**
     * 能力视图所属人
     */
    @SecondaryKey(relate = Relationship.MANY_TO_ONE)
    private String      ownIdentityName;
    /**
     * 能力视图包含的能力列表
     */
    private Set<String> abilityIdSet;

    public AbilityPackage() {
        this.abilityIdSet = new HashSet<String>();
    }

    public String getId() {
        setId();
        return id;
    }

    public void setId() {
        id = new StringBuffer().append(packageName).append(Constants.PK_SEP).append(ownIdentityName).toString();
    }

    public String getPackageName() {
        return packageName;
    }

    public void setPackageName(String packageName) {
        this.packageName = packageName;
    }

    public String getOwnIdentityName() {
        return ownIdentityName;
    }

    public void setOwnIdentityName(String ownIdentityName) {
        this.ownIdentityName = ownIdentityName;
    }

    public Set<String> getAbilityIdSet() {
        return abilityIdSet;
    }

    public void addAbility(Ability ability) {
        this.abilityIdSet.add(ability.getId());
    }

    public void addAbility(String abilityId) {
        this.abilityIdSet.add(abilityId);
    }

    public void removeAbility(String abilityId) {
        this.abilityIdSet.remove(abilityId);
    }
}
